package com.viphuli.app.tool.common;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class PerferencesHelper {
	private static final PerferencesHelper instance = new PerferencesHelper();
	private static final String PREFERENCES_NAME = "com.viphuli.app";

	private PerferencesHelper() {
	}

	public static PerferencesHelper getInstance() {
		return instance;
	}

	public void save(String key, String value) {

		SharedPreferences pref = MyApp.getInstance().getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
		Editor editor = pref.edit();
		editor.putString(key, value);
		editor.commit();
	}
	
	public String read(String key) {

		SharedPreferences pref = MyApp.getInstance().getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
		String value = pref.getString(key, "");

		return value;
	}
	
	public void saveBoolean(String key, Boolean value) {

		SharedPreferences pref = MyApp.getInstance().getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
		Editor editor = pref.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}

	public boolean readBoolean(String key, boolean def) {

		SharedPreferences pref = MyApp.getInstance().getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
		boolean value = pref.getBoolean(key, def);

		return value;
	}

	public void saveInt(String key, int value) {

		SharedPreferences pref = MyApp.getInstance().getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
		Editor editor = pref.edit();
		editor.putInt(key, value);
		editor.commit();
	}

	public int readInt(String key) {

		SharedPreferences pref = MyApp.getInstance().getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
		int value = pref.getInt(key, 0);

		return value;
	}
}
